<?php
/**
 * Created by PhpStorm.
 * User: 87393
 * Date: 2019-03-27
 * Time: 16:35
 */

namespace App\Http\Controllers\Admin\View;


use App\Http\Controllers\Controller;
use App\Http\Repositories\Services\IType;
use App\Http\Requests\Admin\TypeCreateDTO;
use App\Http\Requests\Admin\TypeUpdateDTO;
use App\Util\ResultsVo;
use Illuminate\Support\Facades\Lang;

class TypeController extends Controller
{
    protected $typeService;
    public function __construct(IType $typeService)
    {
        $this->typeService = $typeService;
    }

    public function page(){
        $dao = $this->typeService->findTree();
        return view('admin.type.index');
    }

    public function store(){
        $tree = $this->typeService->findTree();
        return view('admin.type.create',['tree'=>$tree]);
}

    /*public function store(TypeCreateDTO $createDTO){
        $this->typeService->store($createDTO);
        return response()->json(new ResultsVo(['data'=>true,'message'=>Lang::get('response.success'),'jump'=>'/admin/type']));
    }*/

    public function edit($id){
        $dao = $this->typeService->findId($id);
        $tree = $this->typeService->findTree();
        return view('admin.type.edit',['dao'=>$dao,'tree'=>$tree]);
    }

    public function update(TypeUpdateDTO $updateDTO,$id){
        $this->typeService->update($updateDTO,$id);
        return response()->json(new ResultsVo(['data'=>true,'message'=>Lang::get('response.success'),'jump'=>'/admin/type']));
    }

    public function state( ){

    }
}